package control;

import java.util.Scanner;

public class UserControl{

    private static Scanner in;

    public static void branchControl() {
        double temp = 0;
        int total = 0;

        System.out.println("输入整数:");
        if (in.hasNextInt()) {
            int i = in.nextInt();
            System.out.println("Right!"+i);
        }else {
            System.out.println("Error!");
        }

        System.out.println("输入小数:");
        if (in.hasNextDouble()) {
            double i = in.nextDouble();
            System.out.println("Right!"+i);
        }else {
            System.out.println("Error!");
        }

        while (in.hasNextDouble()) {
            total++;
            temp = in.nextDouble();
            System.out.println("Temp:"+temp);
        }
    }

    public static void main(String[] args) {
        //扫描器对象，接收数据流
        in = new Scanner(System.in);

        //next与nextLine的区别?
        System.out.println("Use nextLine:");
        String next = in.nextLine();
        System.out.println("Output:"+next);

        System.out.println("Use next:");
        String str = in.next();
        System.out.println("Output:"+str);

        branchControl();
        //IO流的类不关闭会一直占用资源，养成习惯
        in.close();
    }
}
